import rand from './rand';
function generateSimilarNetwork(baseMatrix) {
  let len = baseMatrix.length;
  let matrix = JSON.parse(JSON.stringify(baseMatrix));
  let deleteNodeNum = rand(Math.floor(len * 0.05), Math.floor(len * 0.1));
  let changeEdgeNum = deleteNodeNum * deleteNodeNum;
  for (let i = 0; i < changeEdgeNum; i++) {
    let source;
    let target;
    while (true) {
      source = rand(0, len - 1);
      target = rand(0, len - 1);
      if (source !== target) break;
    }
    if (matrix[source][target] === 1) {
      if (Math.random() < 0.8) {
        matrix[source][target] = 0;
        matrix[target][source] = 0;
      } else {
        matrix[source][target] = -1;
        matrix[target][source] = -1;
      }
    } else if (matrix[source][target] === -1) {
      if (Math.random() < 0.8) {
        matrix[source][target] = 0;
        matrix[target][source] = 0;
      } else {
        matrix[target][source] = 1;
        matrix[source][target] = 1;
      }
    }
    if (matrix[source][target] === 0) {
      if (Math.random() < 0.1) {
        matrix[source][target] = 1;
        matrix[target][source] = 1;
      } else if (Math.random() < 0.1) {
        matrix[source][target] = -1;
        matrix[target][source] = -1;
      }
    }
  }
  matrix = matrix.slice(0, len - deleteNodeNum);
  matrix = matrix.map(item => item.slice(0, len - deleteNodeNum));
  return matrix;
}
export default generateSimilarNetwork;
